//
//  MyButtonView.m
//  RoadLine
//
//  Created by dllo on 15/4/21.
//  Copyright (c) 2015年 RedFireNoodles. All rights reserved.
//

#import "MyButtonView.h"
#import "Constants.h"
#import "Singleton.h"

@implementation MyButtonView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creat];
    }
    return self;
    
}

-(void)creat{
    
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width-20,25)];
    self.label.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    [self addSubview:self.label];
    [_label release];
    
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width-20, 0, 20, 25)];
    self.imageView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    self.imageView.image = [UIImage imageNamed:kButtonImageName];
    [self addSubview:self.imageView];
    [_imageView release];
    
    if ([Singleton shareSingleton].isNight) {
        [self setNightDayModel];
    } else {
        [self setLightDayModel];
    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setNightDayModel) name:@"NightDayNSNotification" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setLightDayModel) name:@"LightDayNSNotification" object:nil];
}

- (void)setLightDayModel {
    self.label.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
    self.label.textColor = [UIColor blackColor];
    self.imageView.backgroundColor = [UIColor colorWithRed:250/255.0 green:245/255.0 blue:232/255.0 alpha:1];
}

- (void)setNightDayModel {
    self.label.textColor = [UIColor whiteColor];
    self.label.backgroundColor = [UIColor blackColor];
    self.imageView.backgroundColor = [UIColor blackColor];
}

- (void)dealloc{
    [_imageView release];
    [_label release];
    // 必须在dealloc方法中移除观察
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}

@end
